package com.xqboss.common.utils.sms;

import cn.hutool.core.lang.Validator;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.xqboss.common.config.properties.SmsProperties;

/**
 * @author Administrator
 * @Description: 初始化短信client
 */
public class SmsClient {

    private static DefaultAcsClient client;

    /**
     * 创建远程连接客户端对象
     */
    public static DefaultAcsClient getClient() {
        if (client == null) {
            DefaultProfile profile = DefaultProfile.getProfile(
                    SmsProperties.REGION_Id,
                    SmsProperties.KEY_ID,
                    SmsProperties.KEY_SECRET);
            client = new DefaultAcsClient(profile);
        }
        return client;
    }

    /**
     * 创建远程连接的请求参数
     */
    public static CommonRequest getCommonRequest() {
        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.putQueryParameter("RegionId", SmsProperties.REGION_Id);
        request.putQueryParameter("SignName", SmsProperties.SIGN_NAME);
        return request;
    }

    public static void main(String[] args) {
        boolean mobile = Validator.isMobile("106980096511");
        System.out.println("mobile = " + mobile);
    }
}
